
package com.amt.configure;

import com.amt.util.StringUtil;
import com.amt.util.SystemConstantUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;


/**
 * @Title: BehaviorAspect.java
 * @Package com.amt.configure
 * @Description: TODO(用户行为统计切面)
 * @author 江伟
 * @date 2021年01月26日 上午10:44:54 Copyright (c) ©1994-2021 Scjydz.com All Rights
 *       Reserved.
 */
@Aspect
@Component
public class BehaviorAspect {
	
	@Pointcut("@annotation(com.amt.configure.Analyze)")
	public void behavior() {
		
	}
	
	@After("behavior()")
	public void doConcurrentOperation(JoinPoint pjp) throws Throwable {
		// 获取拦截的方法名
		MethodSignature msig = (MethodSignature) pjp.getSignature();
		// 返回被织入增加处理目标对象
		Object target = pjp.getTarget();
		// 为了获取注解信息
		Method currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes());
		// 获取注解信息
		Analyze annotation = currentMethod.getAnnotation(Analyze.class);
		if(StringUtil.isNotEmpty(annotation.type())) {
			switch (annotation.type()) {
			case "report":
				SystemConstantUtil.REPORT_NUMBER++;
				break;
			case "guidance":
				SystemConstantUtil.GUIDANCE_NUMBER++;
				break;
			default:
				break;
			}
		}
	}
}
